package com.GameComponent;

import com.Core.GameEngine;
import com.Triocean.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.os.Process;

public class TitleScreen extends Activity
{	@Override
	public void onCreate(Bundle savedInstanceState)
	{	super.onCreate(savedInstanceState);
		setContentView(R.layout.title_screen);
		
		ImageView startGame	= (ImageView)findViewById(R.id.btnStart);
		ImageView exitGame	= (ImageView)findViewById(R.id.btnExit);
		
		startGame.setOnClickListener(new OnClickListener()
		{	@Override
			public void onClick(View v)
			{	if (GameEngine.dataAllLoaded)
				{	new Handler().postDelayed
					(	new Thread()
						{	@Override
							public void run()
							{	Intent mainGame = new Intent(GameEngine.globalContext, MainGame.class);
								TitleScreen.this.startActivity(mainGame);
								TitleScreen.this.finish();
								TitleScreen.this.overridePendingTransition(R.layout.fadein, R.layout.fadeout);
							}
						},
						GameEngine.SPLASH_SCREEN_TIME
					);
				}
			}
		});
		exitGame.setOnClickListener(new OnClickListener()
		{	@Override
			public void onClick(View v)
			{	Intent bgMusic = new Intent(GameEngine.globalContext, BackgroundMusic.class);
				GameEngine.globalContext.stopService(bgMusic);
				GameEngine.musicThread.interrupt();
				Process.killProcess(Process.myPid());
			}
		});
	}
}
